//
//  VistorLoginView.swift
//  LDMicroblog
//
//  Created by pro on 15/8/30.
//  Copyright (c) 2015年 pro. All rights reserved.
//

import UIKit

protocol VistorLoginViewDelegate: NSObjectProtocol {
    //注册
    func vistorLoginViewResgisterBtnDidSelected()
    
    //登录
    func vistorLoginViewLoginBtnDidSelected()
}


class VistorLoginView: UIView {

    weak var delegate: VistorLoginViewDelegate?
    
    @IBOutlet weak var bigImgView: UIImageView!
    
    @IBOutlet weak var smallImgView: UIImageView!
    
    @IBOutlet weak var bgImgView: UIImageView!
    
    @IBOutlet weak var messageLabel: UILabel!
    
    @IBAction func loginBtnClick(sender: AnyObject) {
        //?判断代理方法有没有实现，实现了就执行，没实现就不执行
        delegate?.vistorLoginViewLoginBtnDidSelected()
    }
    
    @IBAction func registerBtnClick(sender: AnyObject) {
        delegate?.vistorLoginViewResgisterBtnDidSelected()
    }
    
    //MARK:--设置画面
    func setupView(imgName: String, message: String, isHome: Bool) {
    
        if isHome {//首页
        
            smallImgView.image = UIImage(named: imgName)
            smallImgView.hidden = false
            
            startAnimation()
//            if bigImgView.layer.animationForKey("rotationAnim") == nil {
//                startAnimation()
//            }
            
        
        }else {//不是首页
        
            bigImgView.image = UIImage(named: imgName)
            smallImgView.hidden = true
            
//            stopAnimation()
        }
        
        messageLabel.text = message
        
    }
    //MARK:--开始动画基本信息
    func startAnimation(){
    
        let anim = CABasicAnimation(keyPath: "transform.rotation")//transform.rotation
        anim.toValue = 2 * M_PI
        anim.duration = 20.0
        anim.repeatCount = MAXFLOAT
//        anim.removedOnCompletion = false
        
        bigImgView.layer.addAnimation(anim, forKey: nil)//给key赋值"rotationAnim"对动画形成强引用
        
    }
    
    //MARK:--停止动画
//    func stopAnimation() {
//    
//        bigImgView.layer.removeAllAnimations()
//    }
}
